#include<iostream>
using namespace std;
typedef long long LL;
const int N = 110, M = 1010;
char s[N][M];
int n, m;
int x, y;
int main()
{
	int t;
	cin >> t;
	while (t--) {
		cin >> n >> m >> x >> y;
		for (int i = 1; i <= n; i++) {
			for (int j = 1; j <= m; j++) {
				cin >> s[i][j];
			}
		}
		bool flag = 0;
		LL ans = 0;
		if (2 * x > y)flag = 1;
		for (int i = 1; i <= n; i++) {
			int cnt = 0;
			for (int j = 1; j <= m; j++) {
				if (s[i][j] == '.')cnt++;
				else {
					if (flag) {
						ans += (cnt / 2) * y;
						if (cnt & 1)ans += x;
					}
					else {
						ans += cnt * x;
					}
					cnt = 0;
				}
			}
			if (cnt) {
				if (flag) {
					ans += (cnt / 2) * y;
					if (cnt & 1)ans += x;
				}
				else {
					ans += cnt * x;
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}